home *** CD-ROM | disk | FTP | other *** search
/ Gekkan Dennou Club 147 / Gekkan Dennou Club - 2000.8 Vol. 147 (Japan).7z / Gekkan Dennou Club - 2000.8 Vol. 147 (Japan) (Track 1).bin / tools / zmc3v078 / zmc3v078.lzh / SRCSV078.LZH / MAKEZMD2.C < prev    next >
Text File  |  2000-05-09  |  47KB  |  1,695 lines

  1. /* ==================================
  2.      ZMS->ZMD playing track compile
  3.    ================================== */
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <ctype.h>
  8. #include <string.h>
  9. #include "switch.h"
  10. #include "parsesub.h"
  11. #include "makezmd.h"
  12. #include "makezmd1.h"
  13. #include "makezmd3.h"
  14. #include "bracket.h"
  15. #include "velo.h"
  16. #include "etc.h"
  17.  
  18.  
  19. #include "structs.h"
  20. #include "structs2.h"
  21. TRKCHINF *makeZmdMain(TRKCHINF *trkdata,UBYTE *zms, UBYTE **zms2,
  22.                         COMMONINF *cominf, DWORD *totalstep);
  23. UBYTE *makeZmdNote(UBYTE *zms,TRKCHINF *trkdata, const BYTE target[],
  24.                         TRKINF *trkinf,COMMONINF *cominf);
  25. UBYTE *makeZmdNote1(UBYTE *zms, const int Trk,TRKINF *trkinf,BYTE *note);
  26. UBYTE *getGate(UBYTE *zms, const int Trk,TRKINF *trkinf,UWORD step, UWORD *gate,int *err,
  27.                         COMMONINF *cominf);
  28. /* UWORD getGate1(const BYTE target[],TRKINF *trkinf,int trk,UWORD Step); */
  29. UBYTE *makePortChord(UBYTE *zms, const int Trk,
  30.                         TRKINF *trkinf,COMMONINF *cominf,
  31.                         const UBYTE endchar,char allowcamma,
  32.                         VELOETCVAR v[],BYTE note[],int *notes,
  33.                         UWORD *step_, UWORD *gate_, UWORD *gate0,
  34.                         WORD *delay, WORD *ptime);
  35. UBYTE *makePlayTrack(UBYTE *zms,TRKINF *trkinf,TRKCHINF *trkdata,
  36.                         COMMONINF *cominf,BYTE target[],int mode);
  37.  
  38.  
  39. extern DWORD line,linebak;
  40. extern char *linebuf;
  41. extern LINEDATA *ld;
  42.  
  43.  
  44.  
  45.  
  46.  
  47. TRKCHINF *makeZmdMain(TRKCHINF *trkdata,UBYTE *zms, UBYTE **zms2,
  48.                         COMMONINF *cominf, DWORD *totalstep)
  49. {
  50.     int            i, stat = 0, didPlayCommand = 0;
  51.     BYTE        *target;
  52.     TRKINF        *trkinf;
  53.  
  54.     int trk, err;
  55.     DWORD tmpDWORD;
  56.     UBYTE *zms_;
  57.     UBYTE tmpUBYTE;
  58.     DWORD line_;
  59.     char *linebuf_;
  60.     LINEDATA *ld_;
  61.  
  62.     target = (BYTE*)emalloc(sizeof(BYTE) * cominf->maxtrk,"target");
  63.     trkinf = (TRKINF*)emalloc(sizeof(TRKINF) * cominf->maxtrk,"trkinf");
  64.  
  65.     for (i = 1; i < cominf->maxtrk; i++) {
  66. /*    for (i = 1; i < cominf->trkassign[i] >= 0; i++) {*/
  67.         initTrkInf(&trkinf[i], cominf);
  68.         trkinf[i].l = (LOOPDATA*)NULL;
  69.         trkinf[i].d = (LOOPDATA*)NULL;
  70.         trkinf[i].r = (RENP*)NULL;
  71.         trkinf[i].s = (CHKSTEP*)NULL;
  72.         trkinf[i].c = (CHKCHORD*)NULL;
  73.         initTrkInf2(&trkinf[i], i);
  74.     }
  75.  
  76.     if (stricmp2(zms, ".track")) {                /*    not .track {.. */
  77.         if (*zms == '(') {
  78.             UBYTE *zms_ = zms;
  79.             zms = skipSpc(zms);
  80.             if (*zms != 't' && *zms != 'T') {    /* not (T... */
  81.                 target[0] = 1;
  82.                 target[1] = -1;
  83.                 cominf->trackmode = 0;
  84.             }
  85.             zms = zms_;
  86.         } else {
  87.             target[0] = 1;
  88.             target[1] = -1;
  89.             cominf->trackmode = 0;
  90.         }
  91.     }
  92.  
  93.     while (1) {
  94.         zms = skipSpcCr(zms);
  95.         /* data = data_; */
  96.  
  97.         zms_ = zms + 1;        /* cant write this line inner switch{} */
  98.         linebuf_ = linebuf;
  99.         line_ = linebak = line;
  100.         ld_ = ld;
  101.  
  102.         switch(*zms++) {
  103. #ifdef A
  104.             case 0x1a:        /* for MS-DOS */
  105. #endif
  106.             case 0xFF:                                    /* EOF */
  107.                 for (trk = 0; cominf->trkassign[trk] >= 0; trk++) {
  108.                     const int Trk = cominf->trkassign[trk];
  109.                     *trkdata[Trk].zmd++ = 0xFF;
  110.                 }
  111.                 stat = -1;
  112.                 break;
  113.             case '@':
  114. /*OK*/            zms = makeZmdAtmark(zms,trkdata,target,trkinf,cominf);
  115.                 break;
  116.             case '\"':                                    /* @j old style || extended 8chord */
  117. /*OK*/            zms = getnum2(zms, &tmpDWORD, &err);
  118.                 if (err < 0) {                            /* no value -> extended chord*/
  119.                     zms = makeZmdChord(zms,trkdata,target,trkinf,1,cominf);
  120.                     zmserror("\"..\" can use only for zmc2.",line_,linebuf_,zms,4,1);
  121.                     for (trk = 0; target[trk] >= 0; trk++) {
  122.                         trkinf[target[trk]].noteon = 1;
  123.                     }
  124.                 } else {                                /* @j old style */
  125.                     for (trk = 0; target[trk] >= 0; trk++) {
  126.                         const int Trk = target[trk];
  127.  
  128.                         *trkdata[Trk].zmd++ = 0x9e;
  129.                         *trkdata[Trk].zmd++ = (tmpDWORD)? 1 : 0;
  130.                     }
  131.                 }
  132.                 break;
  133.             case '|':                                    /* loop */
  134.             case ':':
  135. /*OK*/            zms = makeZmdLoop1(--zms,trkdata,target,trkinf);
  136.                 break;
  137.             case '[':                                    /* [..] commands */
  138.                 zms = makeZmdCommand(zms,trkdata,target,trkinf,cominf);
  139.                 break;
  140.             case '\\':                                    /* fadein/fadeout */
  141. /*Ok*/            for (trk = 0; target[trk] >= 0; trk++) {
  142.                     const int Trk = target[trk];
  143.                     line = line_;
  144.                     ld = ld_;
  145.                     zms = getnum2(zms_, &tmpDWORD, &err);
  146.                     if (err < 0) {
  147.                         tmpDWORD = 0;    /* trkinf[target[trk]].fadeout; */
  148.                     }
  149.                     if (tmpDWORD < -128 || 127 < tmpDWORD) {
  150.                         zmserror("fadein/out parameter is out of range(-128 - 127).",line_,linebuf_,zms_,3,1);
  151.                     }
  152.                     *trkdata[Trk].zmd++ = 0xD6;
  153.                     putWord(trkdata[Trk].zmd, 0x7FFE);
  154.                     trkdata[Trk].zmd += 2;
  155.                     putWord(trkdata[Trk].zmd, 0);        /* current track */
  156.                     trkdata[Trk].zmd += 2;
  157.                     *trkdata[Trk].zmd++ = 7;
  158.                     if (tmpDWORD >= 0) {
  159.                         putWord(trkdata[Trk].zmd, tmpDWORD * 0x100);
  160.                         trkdata[Trk].zmd += 2;
  161.                         *trkdata[Trk].zmd++ = 0x80;
  162.                         *trkdata[Trk].zmd++ = 0;
  163.                     } else {
  164.                         putWord(trkdata[Trk].zmd, -tmpDWORD * 0x100);
  165.                         trkdata[Trk].zmd += 2;
  166.                         *trkdata[Trk].zmd++ = 0;
  167.                         *trkdata[Trk].zmd++ = 0x80;
  168.                     }
  169.                 }
  170.                 break;
  171.             case '=':                                    /* switches */
  172. /*OK*/            zms = getnum2(zms,&tmpDWORD,&err);
  173.                 if (err < 0) {
  174.                     tmpDWORD = 0;
  175.                 }
  176.                 for (trk = 0; target[trk] >= 0; trk++) {
  177.                     const int Trk = target[trk];
  178.                     const UBYTE cmd[4] = { 0x99, 0x98, 0xB3, 0x96 };
  179.                     int i;
  180.                     UBYTE match = 0x08;
  181.  
  182.                     for (i = 0; i < 4; i++) {
  183.                         const UWORD data = (tmpDWORD & match)? 2 : 0;
  184.  
  185.                         *trkdata[Trk].zmd++ = cmd[i];
  186.                         if (i == 2) {
  187.                             putWord(trkdata[Trk].zmd, data);
  188.                             trkdata[Trk].zmd += 2;
  189.                         } else {
  190.                             *trkdata[Trk].zmd++ = data;
  191.                         }
  192.                         match /= 2;
  193.                     }
  194.  
  195.                     trkinf[Trk].veloseqsw = (tmpDWORD & 0x10)? 1 : 0;
  196.                 }
  197.                 break;
  198.             case '~':    case '_':                        /* relative velocity up/down*/
  199. /*tenuki */        tmpUBYTE = *(zms - 1);                    /* keep MML */
  200.  
  201.                 for (trk = 0; target[trk] >= 0; trk++) {
  202.                     const int Trk = target[trk];
  203.                     DWORD v = 0;
  204.                     int err;
  205.  
  206.                     line = line_;
  207.                     ld = ld_;
  208.                     zms = zms_ - 1;
  209.                     do {
  210.                         DWORD vol;
  211.                         zms = getnum2(zms + 1, &vol, &err);
  212.                         if (err >= 0) {
  213.                             trkinf[Trk].relvol = vol;
  214.                         }
  215.                         v += trkinf[Trk].relvol;
  216.                         zms = skipSpc(zms);
  217.                     } while (*zms == tmpUBYTE);
  218.  
  219.                     *trkdata[Trk].zmd++ = 0x91;
  220.                     *trkdata[Trk].zmd++ = (tmpUBYTE == '~')? v : -v;
  221. #ifdef AAA
  222. /* (BEGIN FM/ADPCMsupport by Mamiya */
  223.                     if (checkInternalDevice(trkdata,Trk) & 1) {
  224.                         if (tmpUBYTE == '~')
  225.                             v = trkinf[Trk].velou.var[0] + v ;
  226.                         else
  227.                             v = trkinf[Trk].velou.var[0] - v ;
  228.                         v = (v < 0) ? 0 : ((v > 127) ? 127 : v) ;
  229.                         trkinf[Trk].velou.var[0] = v ;
  230.                     }
  231. /* FM/ADPCMsupport by Mamiya END) */
  232. #endif
  233.                 }
  234.                 break;
  235.             case '<':    case '>':                        /* octave up/down */
  236. /*OK*/            {
  237.                     UBYTE *zms_ = --zms;
  238.                     for (trk = 0; target[trk] >= 0; trk++) {
  239.                         const int Trk = target[trk];
  240.                         zms = checkOctaveChange(zms_,trkinf,Trk);
  241.                     }
  242.                 }
  243.                 break;
  244.             case '`':                                /* ` */
  245. /*OK*/            makeZmdAllSoundOff(trkdata, target);
  246.                 break;
  247.             case '{':                                    /* renpu start */
  248.                 zms = skipSpcCr(zms);
  249. /*OK*/            if (*zms == '{') {                        /*  */
  250.                     for (trk = 0; target[trk] >= 0; trk++) {
  251.                         const int Trk = target[trk];
  252.                         char s[32];
  253.                         sprintf(s,"trkinf[%d].s->next",Trk);
  254.                         trkinf[Trk].s->next       = (CHKSTEP*)emalloc(sizeof(CHKSTEP) * 1, s);
  255.                         trkinf[Trk].s->next->prev = trkinf[Trk].s;
  256.                         trkinf[Trk].s             = trkinf[Trk].s->next;
  257.                         trkinf[Trk].s->next       = (CHKSTEP*)NULL;
  258.                         trkinf[Trk].s->step       = trkinf[Trk].total;    /*0;*/
  259.                     }
  260.                     zms++;
  261.                     zmserror("{{..}} can use only for zmc2.",line_,linebuf_,zms,4,1);
  262.                 } else {
  263.                     for (trk = 0; target[trk] >= 0; trk++) {
  264.                         if (trkinf[target[trk]].renpnotes) {
  265.                             zmserror("renpu{..} can't nest.",line,linebuf,zms,0,1);
  266.                         }
  267.                         trkinf[target[trk]].renpnotes = 1;
  268.                     }
  269.                 }
  270.                 break;
  271.             case '}':                                    /* renpu end */
  272. /*OK*/            zms = skipSpcCr(zms);
  273.                 if (*zms == '}') {                        /* }} */
  274.                     for (trk = 0; target[trk] >= 0; trk++) {
  275.                         const int Trk = target[trk];
  276.                         UWORD step_;
  277.                         UWORD usedstep = (UWORD)(trkinf[Trk].total - trkinf[Trk].s->step);
  278.  
  279.                         if (trkinf[Trk].s->prev == NULL) {
  280.                             zmserror("no {{  found.",line,linebuf,zms,0,1);
  281.                         }
  282.                         line = line_;
  283.                         ld = ld_;
  284.                         zms = getStep(zms + 1, &step_, trkinf[Trk].Step,&err,cominf);
  285.                         zms = skipSpcCr(zms);
  286.                         zms = set98Tie(zms,&step_,trkinf[Trk].Step,cominf, &err);
  287.  
  288.                         if (step_ != usedstep) {    /* (UWORD)trkinf[Trk].s->step) { */
  289.                             char str[128];
  290.                             sprintf(str,"{{..}}: %d ticks are reserved, but %d are in use.",
  291.                                         step_, usedstep);
  292.                             zmserror(str,line_,linebuf_,zms_,2,1);
  293.                             zmserror("{{..}} can use only for zmc2.",line_,linebuf_,zms_,4,1);
  294.                         }
  295.  
  296.                         trkinf[Trk].s = trkinf[Trk].s->prev;
  297.                         efree(trkinf[Trk].s->next,"trkinf[Trk].s->next");
  298.                         trkinf[Trk].s->next = NULL;
  299. #ifdef AAA
  300.                         if (trkinf[Trk].s->prev) {
  301.                             trkinf[Trk].s->step += step_;
  302.                         }
  303. #endif
  304.                     }
  305.                 } else {
  306.                     zms = makeRenpuStepGate(zms,target,trkdata,trkinf,cominf);
  307.                 }
  308.                 break;
  309.             case 'a':    case 'A':                        /* tone */
  310.             case 'b':    case 'B':
  311.             case 'c':    case 'C':
  312.             case 'd':    case 'D':
  313.             case 'e':    case 'E':
  314.             case 'f':    case 'F':
  315.             case 'g':    case 'G':
  316. /*OK*/            /* [a-g](!+|[#+b-])*step,*gate,veloz[&] */
  317.                 zms = makeZmdNote(zms,trkdata,target,trkinf,cominf);
  318.                 for (trk = 0; target[trk] >= 0; trk++) {
  319.                     trkinf[target[trk]].noteon = 1;
  320.                 }
  321.                 break;
  322.             case 'h':    case 'H':                        /* wave-synchronous mode set */
  323. /*
  324.                 zms = makeZmdManyParas(zms,trkdata,target,line_,linebuf_,
  325.                                         0x9C, 0xFF, 2, 1, 1,
  326.                                         "i: too many parameters.",
  327.                                         "i: can't use relational parameters.",
  328.                                         "");
  329. */
  330. /*OK*/            {
  331.                     int err;
  332.                     DWORD tmp;
  333.  
  334.                     zms = getnum2(zms,&tmp,&err);
  335.                     if (err > 0) {
  336.                         zmserror("H error.",line,linebuf,zms,0,1);
  337.                     } else if (!err) {
  338.                         int trk;
  339.                         for (trk = 0; target[trk] >= 0; trk++) {
  340.                             const int Trk = target[trk];
  341.                             *trkdata[Trk].zmd++ = 0x97;
  342.                             *trkdata[Trk].zmd++ = (tmp)? 0 : 0x80;
  343.                             putWord(trkdata[Trk].zmd, 1);
  344.                             trkdata[Trk].zmd += 2;
  345.                         }
  346.                     }
  347.  
  348.                     if (*zms == ',') {
  349.                         zms = getnum2(++zms,&tmp,&err);
  350.                         if (err > 0) {
  351.                             zmserror("H error.",line,linebuf,zms,0,1);
  352.                         } else if (!err) {
  353.                             int trk;
  354.                             for (trk = 0; target[trk] >= 0; trk++) {
  355.                                 const int Trk = target[trk];
  356.                                 *trkdata[Trk].zmd++ = 0xB5;
  357.                                 *trkdata[Trk].zmd++ = 0x00;
  358.                                 *trkdata[Trk].zmd++ = (tmp)? 0 : 0x80;
  359.                                 putWord(trkdata[Trk].zmd, 1);
  360.                                 trkdata[Trk].zmd += 2;
  361.                             }
  362.                         }
  363.                     }
  364.                 }
  365.                 break;
  366. /*OK*/        case 'i':    case 'I':                        /* bank select */
  367.                 zms = makeZmdProgramBankChange(zms, trkdata, target);
  368.                 break;
  369.             case 'k':    case 'K':                        /* key transpose */
  370. /*OK*/            zms = get1AbsPara(zms,&tmpDWORD,-128,127,
  371.                         "key transpose parameter is out of range(-128 - 127).",
  372.                         "`k'(key transpose) must be followed to its parameter.");
  373.  
  374.                 for (trk = 0; target[trk] >= 0; trk++) {
  375.                     *trkdata[target[trk]].zmd++ = 0xAB;
  376.                     *trkdata[target[trk]].zmd++ = trkinf[target[trk]].transpose = tmpDWORD;
  377.                 }
  378.                 break;
  379.             case 'l':    case 'L':                        /* set default step */
  380. /*OK*/            for (trk = 0; target[trk] >= 0; trk++) {
  381.                     UWORD step;
  382.                     int err;
  383.                     line = line_;
  384.                     ld = ld_;
  385.                     zms = getStep(zms_, &step, trkinf[target[trk]].Step, &err,cominf);
  386.                     trkinf[target[trk]].Step = step;
  387.                 }
  388.                 break;
  389.             case 'm':    case 'M':                        /* MIDI pitch modulation mode set */
  390. /*
  391.                 zms = makeZmdManyParas(zms,trkdata,target,line_,linebuf_,
  392.                                         0x99, 0xFF, 2, 1, 1,
  393.                                         "m: too many parameters.",
  394.                                         "m: can't use relational parameters.",
  395.                                         "");
  396. */
  397. /*OK*/
  398.                 {
  399.                     int err;
  400.                     DWORD tmp;
  401.  
  402.                     zms = getnum2(zms,&tmp,&err);
  403.                     if (err > 0) {
  404.                         zmserror("M error.",line,linebuf,zms,0,1);
  405.                     } else if (!err) {
  406.                         int trk;
  407.                         for (trk = 0; target[trk] >= 0; trk++) {
  408.                             const int Trk = target[trk];
  409.                             *trkdata[Trk].zmd++ = 0x95;
  410.                             *trkdata[Trk].zmd++ = tmp - 1;
  411.                         }
  412.                     }
  413.  
  414.                     if (*zms == ',') {
  415.                         zms = getnum2(++zms,&tmp,&err);
  416.                         if (err > 0) {
  417.                             zmserror("M error.",line,linebuf,zms,0,1);
  418.                         } else if (!err) {
  419.                             int trk;
  420.                             for (trk = 0; target[trk] >= 0; trk++) {
  421.                                 const int Trk = target[trk];
  422.                                 *trkdata[Trk].zmd++ = 0xB4;
  423.                                 *trkdata[Trk].zmd++ = 0x00;
  424.                                 *trkdata[Trk].zmd++ = tmp - 1;    /* (tmp)? 1 : -1; */
  425.                             }
  426.                         }
  427.                     }
  428.                 }
  429.                 break;
  430.             case 'n':    case 'N':                        /* channel change */
  431. /*tenuki*/        zms = get1AbsPara(zms,&tmpDWORD,1,32,
  432.                         "channel change parameter is out of range(1 - 32).",
  433.                         "`n'(channel change) must be followed to its parameter.");
  434.  
  435.                 for (trk = 0; target[trk] >= 0; trk++) {
  436.                     BYTE ch = 0;
  437.                     const int Trk = target[trk];
  438.  
  439.                     if (cominf->basech) {                /* (B1) MIDI mode */
  440.                         if (tmpDWORD <= 16) {
  441.                             ch = tmpDWORD + 8;
  442.                         } else if (tmpDWORD <= 8 + 1 + 16) {
  443.                             ch = tmpDWORD - 17;
  444. /* (BEGIN debug??? by Mamiya */
  445.                         } else {
  446.                             ch = tmpDWORD - 1;
  447. /* debug??? by Mamiya END) */
  448.                         }
  449.                     } else {
  450.                         ch = tmpDWORD - 1;
  451.                     }
  452.                     *trkdata[Trk].zmd++ = 0xCC;
  453.                     putWord(trkdata[Trk].zmd, 0x8000);
  454.                     putWord(trkdata[Trk].zmd + 2, ch - 9);
  455.                     trkdata[Trk].zmd += 4;
  456. /*
  457. fprintf(stderr,"%d:%x %x %x %x %x %x %x\n",
  458. Trk,
  459. *(trkdata[Trk].zmd-6),
  460. *(trkdata[Trk].zmd-5),
  461. *(trkdata[Trk].zmd-4),
  462. *(trkdata[Trk].zmd-3),
  463. *(trkdata[Trk].zmd-2),
  464. *(trkdata[Trk].zmd-1),
  465. *(trkdata[Trk].zmd));
  466. */
  467.                 }
  468.                 break;
  469.             case 'o':    case 'O':                        /* octave set */
  470. /*OK*/            {
  471.                     UBYTE *zms_ = --zms;
  472.                     for (trk = 0; target[trk] >= 0; trk++) {
  473.                         const int Trk = target[trk];
  474.                         zms = checkOctaveChange(zms_,trkinf,Trk);
  475.                     }
  476.                 }
  477.                 break;
  478.             case 'p':    case 'P':                        /* panpot set */
  479.                 zms = makeZmdPanpot(zms, trkdata, target, -1);
  480. #ifdef A
  481.                 {
  482. /*tenuki*/            const int tbl[] = {128, 0, 127, 64};
  483.  
  484.                     zms = get1AbsPara(zms,&tmpDWORD,0,3,
  485.                             "panpot parameter is out of range(0-3).",
  486.                             "`p'(panpot set) must be followed to its parameter.");
  487.  
  488.  
  489.                     for (trk = 0; target[trk] >= 0; trk++) {
  490.                         *trkdata[target[trk]].zmd++ = 0xA0;
  491.                         *trkdata[target[trk]].zmd++ = tbl[tmpDWORD];
  492.                     }
  493.                 }
  494. #endif
  495.                 break;
  496.             case 'q':    case 'Q':                        /* quantization */
  497.                 zms = makeZmdQuantize(zms,cominf->qmode,target,trkinf);
  498.                 break;
  499.             case 's':    case 'S':                        /* modulation wave pattern select */
  500. /*
  501.                 zms = makeZmdManyParas(zms,trkdata,target,line_,linebuf_,
  502.                                         0x98, 0xFF, 2, 1, 1,
  503.                                         "s: too many parameters.",
  504.                                         "s: can't use relational parameters.",
  505.                                         "");
  506. */
  507. /*OK*/            {
  508.                     int err;
  509.                     DWORD tmp;
  510.  
  511.                     zms = getnum2(zms,&tmp,&err);
  512.                     if (err > 0) {
  513.                         zmserror("S error.",line,linebuf,zms,0,1);
  514.                     } else if (!err) {
  515.                         int trk;
  516.                         for (trk = 0; target[trk] >= 0; trk++) {
  517.                             const int Trk = target[trk];
  518.                             *trkdata[Trk].zmd++ = 0xB0;
  519.                             if (tmp >= 8) {
  520.                                 tmp += 0x8000 - 8;
  521.                             }
  522.                             putWord(trkdata[Trk].zmd, tmp);
  523.                             trkdata[Trk].zmd += 2;
  524.                         }
  525.                     }
  526.  
  527.                     if (*zms == ',') {
  528.                         zms = getnum2(++zms,&tmp,&err);
  529.                         if (err > 0) {
  530.                             zmserror("H error.",line,linebuf,zms,0,1);
  531.                         } else if (!err) {
  532.                             int trk;
  533.                             for (trk = 0; target[trk] >= 0; trk++) {
  534.                                 const int Trk = target[trk];
  535.                                 *trkdata[Trk].zmd++ = 0xC9;
  536.                                 *trkdata[Trk].zmd++ = 0x00;
  537.                                 if (tmp >= 8) {
  538.                                     tmp += 0x8000 - 8;
  539.                                 }
  540.                                 putWord(trkdata[Trk].zmd, tmp);
  541.                                 trkdata[Trk].zmd += 2;
  542.                             }
  543.                         }
  544.                     }
  545.                 }
  546.                 break;
  547.             case 't':    case 'T':                        /* tempo */
  548.                 zms = makeZmdTempo(zms,trkdata,target,0);
  549.                 break;
  550. /*OK*/        case 'u':    case 'U':                        /* velocity */
  551.                 for (trk = 0; target[trk] >= 0; trk++) {
  552.                     const int Trk = target[trk];
  553.                     BYTE rel = 0;
  554.                     DWORD velo;
  555.                     int err;
  556.  
  557.                     line = line_;
  558.                     ld = ld_;
  559.                     zms = skipSpcCr(zms_);
  560.                     if (*zms == '+') {
  561.                         rel = 1;
  562.                     } else if (*zms == '-') {
  563.                         rel = -1;
  564.                     }
  565.                     zms = getnum2(zms, &velo, &err);
  566.  
  567.                     zms = skipSpcCr(zms);
  568.                     if (*zms == ':' && *(zms + 1) != '|') {
  569.                         DWORD r = trkinf[Trk].velou.var[1];
  570.                         /* DWORD rp = (r)? rand2(r) : 0; */
  571.                         int err2;
  572.                         zms = skipSpcCr(zms + 1);
  573.                         zms = getnum2(zms, &r, &err2);
  574.                         r = abs(r);
  575.                         /* rp = (r && !err2)? rand2(r) : 0; */
  576.                         trkinf[Trk].velou.var[1] = r;
  577.                     }
  578.                     if (rel) {
  579.                         *trkdata[Trk].zmd++ = 0x94;
  580.                         *trkdata[Trk].zmd++ = velo;        /* + rp; */
  581. #ifdef AA
  582.                     } else if (rel < 0) {
  583.                         *trkdata[Trk].zmd++ = 0xCB;
  584.                         *trkdata[Trk].zmd++ = -velo;    /* + rp; */
  585. #endif
  586.                     } else {
  587.                         int v = trkinf[Trk].veloofst;
  588.                         if (err < 0) {                    /* only 'u' */
  589.                             v += trkinf[Trk].velou.var[0];    /* + rp; */
  590.                         } else {
  591.                             trkinf[Trk].velou.var[0] = velo;
  592.                             v += velo;
  593.                             /* *trkdata[Trk].zmd++ = velo; */    /* + rp */;
  594.                         }
  595.  
  596.                         if (v > 127) {
  597.                             v = 127;
  598.                         } else if (v < 0) {
  599.                             v = 0;
  600.                         }
  601.                         *trkdata[Trk].zmd++ = 0x93;
  602.                         *trkdata[Trk].zmd++ = v;
  603.                     }
  604.                     /* trkinf[Trk].veloznum = 0; */
  605.                     setVelocitySequenceMode(trkinf,Trk,0);
  606.                 }
  607.                 break;
  608.             case 'v':    case 'V':                        /* volume */
  609.                 zms = makeZmdVolume(zms, trkdata, target, trkinf, -1);
  610. #ifdef A
  611. /* MIDI OK */
  612.                 for (trk = 0; target[trk] >= 0; trk++) {
  613.                     const int Trk = target[trk];
  614.                     DWORD vol;    /* ,v = trkinf[Trk].vol; */
  615.                     int err;
  616.  
  617.                     line = line_;
  618.                     ld = ld_;
  619.                     zms = getnum2(zms_, &vol, &err);
  620.                     if (err < 0) {                        /* only 'v' */
  621.                         zmserror("`v'(volume change) must be followed to its parameter.",line,linebuf,zms,0,1);
  622.                     } else {
  623.                         if (vol < 0 || vol > 16) {
  624.                             zmserror("volume parameter is out of range.",line,linebuf,zms,0,1);
  625. /* (BEGIN FM/ADPCMsupport by Mamiya */
  626.                         } else if (checkInternalDevice(trkdata,Trk) & 1) {
  627. /*
  628.                             const BYTE vtblFM[17] = {
  629.                                 85,87,90,93,95,98,101,103,106,109,111,114,117,119,122,125,127
  630.                             };
  631. */
  632.                             *trkdata[Trk].zmd++ = 0x90;
  633.                             /* *trkdata[Trk].zmd++ = 127 - vtblFM[vol];
  634.                             trkinf[Trk].velou.var[0] = vtblFM[vol] ; */
  635.                             *trkdata[Trk].zmd++ = 0x80 + vol;
  636.                             trkinf[Trk].velou.var[0] = vol;
  637. /* FM/ADPCMsupport by Mamiya END) */
  638.                         } else {
  639.                             *trkdata[Trk].zmd++ = 0x90;
  640.                             *trkdata[Trk].zmd++ = 0x80 + vol;
  641.                             /* trkinf[Trk].vol = vtbl[vol]; */
  642.                         }
  643.                         trkinf[Trk].volmode = 1;
  644.                     }
  645.                 }
  646. #endif
  647.                 break;
  648.             case 'w':    case 'W':                    /* send/receive track synchoronous*/
  649.                 zms = makeZmdSynchronize(zms, trkdata, target, cominf);
  650.                 break;
  651.             case 'x':    case 'X':                        /* Roland exclusive */
  652.                 zms = makeZmdExclusive(zms, trkdata, target, 0x41);
  653.                 break;
  654.             case 'y':    case 'Y':                        /* control change */
  655.                 zms = makeZmdCChange(zms,trkdata,target);
  656.                 break;
  657.             case 'z':    case 'Z':                        /* velocity sequence */
  658.                 zms = makeZmdVeloSeq(zms,trkdata,target,trkinf);
  659.                 break;
  660.             case 'r':    case 'R':
  661. /*OK*/            for (trk = 0; target[trk] >= 0; trk++) {
  662.                     UWORD step,gate;
  663.                     int err,omitgate;
  664.                     const int Trk = target[trk];
  665.  
  666.                     line = line_;
  667.                     ld = ld_;
  668.                     zms = getStep(zms_, &step, trkinf[Trk].Step,&err,cominf);
  669.                     zms = getGate(zms,Trk,trkinf,step,&gate,&omitgate,cominf);
  670.                     zms = skipSpcCr(zms);
  671.                     if (*zms == ',') {                            /* dummy velocity */
  672.                         zms = getnum2(zms + 1,&tmpDWORD,&err);
  673.                     }
  674.                     zms = setTie(zms, trkdata, Trk, trkinf,
  675.                                     0x80, &step, &gate, 0, omitgate,
  676.                                     trkinf[Trk].Step,cominf,0);
  677.                     incrementStepCounters(&trkinf[Trk],step);
  678. #ifdef AAa
  679.                     if (!trkinf[Trk].renpnotes) {
  680.                         trkinf[Trk].total += step;
  681.                         if (trkinf[Trk].s->prev) {
  682.                             trkinf[Trk].s->step += step;
  683.                         }
  684.                     }
  685. #endif
  686.                     if (gate != 0xFFFF) {
  687.                         freeAllChord(trkinf[Trk].c);
  688.                     }
  689.                 }
  690.                 break;
  691.             case '\'':                                    /* chord */
  692. /*OK*/            zms = makeZmdChord(zms,trkdata,target,trkinf,0,cominf);
  693.                 for (trk = 0; target[trk] >= 0; trk++) {
  694.                     trkinf[target[trk]].noteon = 1;
  695.                 }
  696.                 break;
  697.             case '.':
  698.                 if (!stricmp2(zms, "track")) {
  699.                     zms += 5;
  700.                     zms = makePlayTrack(zms,trkinf,trkdata,cominf,target,0);
  701. #ifdef A
  702.                     if (cominf->trackmode) {
  703.                         zmserror("'}' is not closed.",line,linebuf,zms,0,1);
  704.                     } else {
  705.                         cominf->trackmode = 1;
  706.                     }
  707.  
  708.                         {
  709.                             int c = 0;
  710.                             DWORD trk;
  711.                             int err;
  712.  
  713.                             while (*zms != '{') {
  714.                                 int i = 0 - 1,chkflag = 0;
  715.                                 char errstr[80];
  716.  
  717.                                 zms = getnum2(zms,&trk,&err);
  718.                                 if (err && c == 0 && *zms == '{' ) {    /* (t) */
  719.                                     zmserror("no track number is assigned.",line,linebuf,zms,0,1);
  720.                                 }
  721.  
  722.                                 while (cominf->trkassign[++i] >= 0) {
  723.                                     if (cominf->trkassign[i] == trk) {
  724.                                         chkflag = 1;
  725.                                         break;
  726.                                     }
  727.                                 }
  728.                                 if (!chkflag) {
  729.                                     sprintf(errstr,"trk %d is not assigned.",trk);
  730.                                     zmserror(errstr,line,linebuf,zms,0,1);
  731.                                 }
  732.                                 while (trkdata[trk].backinuse >= 0) {
  733.                                     trk = trkdata[trk].backinuse;
  734.                                 }
  735.                                 target[c++] = trk;
  736.                                 target[c]   = -1;
  737.  
  738.                                 zms = skipSpc(zms);
  739.                                 if (!strchr(",{", *zms)) {
  740.                                     /* char str[128]; */
  741.                                     /* sprintf(str,"%.2x illegal partion character.",*zms); */
  742.                                     zmserror("illegal partition character.",line,linebuf,zms,0,1);
  743.                                 }
  744.                                 if (*zms == ',') {
  745.                                     zms++;
  746.                                 } else if (*zms == 0xFF && *(zms + 1) == 0xFF) {    /* EOF */
  747.                                     zmserror("unexpected EOF.",line,linebuf,zms,0,1);
  748.                                 }
  749.                             }
  750.  
  751.                             zms++;
  752.                         }
  753. #endif
  754.                         break;
  755.                     
  756.                 } else {
  757.                     UBYTE *zms2;
  758.  
  759. /*fprintf(stderr,"[.2s]");*/
  760.                     zms--;
  761.                     makeZmdCommon(trkdata,zms,&zms2,cominf,1);
  762. /*fprintf(stderr,"[.2e]");*/
  763.                     zms = zms2;
  764.                     /* zmserror("UNknown MML",line,linebuf,zms,0,1); */
  765.                     break;
  766.                 }
  767.             case '(':
  768.                 zms = skipSpc(zms);
  769.                 switch(*zms++) {
  770.                     case 'a':    case 'A':    case 'b':    case 'B':    /* portament */
  771.                     case 'c':    case 'C':    case 'd':    case 'D':
  772.                     case 'e':    case 'E':    case 'f':    case 'F':
  773.                     case 'g':    case 'G':    case 'o':    case 'O':
  774.                     case '<':    case '>':
  775.                         zms = makePortament(zms - 1,trkdata,target,trkinf,cominf,')');
  776.                         for (trk = 0; target[trk] >= 0; trk++) {
  777.                             trkinf[target[trk]].noteon = 1;
  778.                         }
  779.                         break;
  780.                     case 'p':    case 'P':                        /* (P...) */
  781. #ifdef AA
  782.                         zms = skiptochr(zms,")");                /* ignore */
  783.                         zms++;
  784.                         break;
  785. #endif
  786.                         if (cominf->trackmode) {
  787.                             zmserror("'}' is not closed.",line,linebuf,zms,0,1);
  788.                         }
  789.  
  790.                         {
  791.                             int c = 0;
  792.                             DWORD trk;
  793.                             int err;
  794.  
  795.                             didPlayCommand = 1;
  796.                             do {
  797.                                 int i = 0 - 1,chkflag = 0, playalltrk = 0;
  798.                                 char errstr[80];
  799.  
  800.                                 zms = getnum2(zms,&trk,&err);
  801.                                 if (!c++) {
  802.                                     int i;
  803.                                     /* loop's 1st time */
  804.                                     if ( err && *zms == ')') {
  805.                                         playalltrk = 1;            /* (p) */
  806.                                     } else {
  807.                                         for (i = 0; cominf->trkassign[i] >= 0; i++) {
  808.                                             const int t = cominf->trkassign[i];
  809.                                             trkdata[t].mute = 0;
  810.                                         }
  811.                                     }
  812.                                 }
  813.                                 while (cominf->trkassign[++i] >= 0) {
  814.                                     int Trk = cominf->trkassign[i];
  815.                                     if (playalltrk || cominf->trkassign[i] == trk) {
  816.                                         chkflag = 1;
  817.                                         do {
  818.                                             trkdata[Trk].mute = 1;
  819.                                             Trk = trkdata[Trk].backinuse;
  820.                                         } while (Trk >= 0);
  821.                                         break;
  822.                                     }
  823.                                 }
  824.                                 if (!chkflag) {
  825.                                     sprintf(errstr,"trk %d is not assigned.",trk);
  826.                                     zmserror(errstr,line,linebuf,zms,0,1);
  827.                                 }
  828.  
  829.                                 zms = skipSpc(zms);
  830.                                 if (!strchr(",)", *zms)) {
  831.                                     /* char str[128]; */
  832.                                     /* sprintf(str,"%.2x illegal partion character.",*zms); */
  833.                                     zmserror("illegal partition character.",line,linebuf,zms,0,1);
  834.                                 }
  835.                                 if (*zms == ',') {
  836.                                     zms++;
  837.                                 } else if (*zms == 0xFF && *(zms + 1) == 0xFF) {    /* EOF */
  838.                                     zmserror("unexpected EOF.",line,linebuf,zms,0,1);
  839.                                 }
  840.                             } while (*zms != ')');
  841.                             if (cominf->backinuse) {    /* there is [back..] trk */
  842.                                 int i;
  843.  
  844.                                 setSwitchVal('z',3);    /* disable the trk deleting */
  845.                                 for (i = 0; cominf->trkassign[i] >= 0; i++) {
  846.                                     int Trk = cominf->trkassign[i];
  847.                                     if (!trkdata[Trk].mute) {
  848.                                         *trkdata[Trk].zmdbuf = 0xFF;
  849.                                         trkdata[Trk].zmd = trkdata[Trk].zmdbuf + 1;
  850.                                     }    /* kill the tracks */
  851.                                 }
  852.                             }
  853.                             zms++;
  854.                         }
  855.                         break;
  856.                     case 't':                                    /* (T...) */
  857.                     case 'T':
  858.                         zms = makePlayTrack(zms,trkinf,trkdata,cominf,target,1);
  859. #ifdef A
  860.                         if (cominf->trackmode) {
  861.                             zmserror("'}' is not closed.",line,linebuf,zms,0,1);
  862.                         } else {
  863.                             cominf->trackmode = 0;
  864.                         }
  865.                         {
  866.                             int c = 0;
  867.                             DWORD trk;
  868.                             int err;
  869.  
  870.                             while (*zms != ')') {
  871.                                 int i = 0 - 1,chkflag = 0;
  872.                                 char errstr[80];
  873.                                 zms = getnum2(zms,&trk,&err);
  874.                                 if (err && c == 0 && *zms == ')' ) {    /* (t) */
  875.                                     zmserror("no track number is assigned.",line,linebuf,zms,0,1);
  876.                                 }
  877.  
  878.                                 while (cominf->trkassign[++i] >= 0) {
  879.                                     if (cominf->trkassign[i] == trk) {
  880.                                         chkflag = 1;
  881.                                         break;
  882.                                     }
  883.                                 }
  884.                                 if (!chkflag) {
  885.                                     sprintf(errstr,"trk %d is not assigned.",trk);
  886.                                     zmserror(errstr,line,linebuf,zms,0,1);
  887.                                 }
  888.                                 while (trkdata[trk].backinuse >= 0) {
  889.                                     trk = trkdata[trk].backinuse;
  890.                                 }
  891.                                 target[c++] = trk;
  892.                                 target[c]   = -1;
  893.  
  894.                                 zms = skipSpc(zms);
  895.                                 if (!strchr(",)", *zms)) {
  896.                                     /* char str[128]; */
  897.                                     /* sprintf(str,"%.2x illegal partion character.",*zms); */
  898.                                     /* fprintf(stderr,"[%c]\n",*zms); */
  899.                                     zmserror("illegal partition character.",line,linebuf,zms,0,1);
  900.                                 }
  901.                                 if (*zms == ',') {
  902.                                     zms++;
  903.                                 } else if (*zms == 0xFF && *(zms + 1) == 0xFF) {    /* EOF */
  904.                                     zmserror("unexpected EOF.",line,linebuf,zms,0,1);
  905.                                 }
  906.                             }
  907.  
  908.                             zms++;
  909. /*
  910.                             printf("Target:");
  911.                             for (trk = 0; target[trk] >= 0; trk++) {
  912.                                 printf("%d,",target[trk]);
  913.                             }
  914.                             printf("\n");
  915. */
  916.                         }
  917. #endif
  918.                         break;
  919.                     default:
  920.                         {
  921.                             UBYTE *zms2;
  922.  
  923.                             zms--;
  924.                             makeZmdCommon(trkdata,zms,&zms2,cominf,1);
  925.                             zms = zms2;
  926.                         }
  927.                         /*zmserror("Unknown MML",line,linebuf,zms,0,1);*/
  928.                         break;
  929.                 }
  930.                 break;
  931.             case '/':
  932.                 zms = skipComment(zms);
  933.                 break;
  934.             case ']':            /* end of [back...] */
  935.                 for (trk = 0; target[trk] >= 0; trk++) {
  936.                     const int Trk     = target[trk];
  937.                     const int fromtrk = cominf->fromtrk[Trk];
  938.  
  939.                     trkdata[Trk].backinuse = -1;
  940.                     if (fromtrk < 0) {
  941.                         zmserror("']' nest error.",line, linebuf,zms,0,1);
  942.                     } else {
  943.                         target[trk] = fromtrk;
  944.                     }
  945.                 }
  946.                 break;
  947. /* (BEGIN FM/ADPCMsupport by Mamiya */
  948.             case 'j':    case 'J':                        /* replay */
  949. /*tenuki*/        zms = makeZmdReplay(zms, trkdata, target);
  950.                 break;
  951. #ifdef A
  952.             case 'j':    case 'J':
  953.                 zms = getnum2(zms_, &tmpDWORD, &err);
  954.                 for (trk = 0; target[trk] >= 0; trk++) {
  955.                     const int Trk = target[trk];
  956.                     if (err < 0) {
  957.                         zmserror("restart(`j') must be followed to its parameter.",line_,linebuf_,zms_,0,1);
  958.                     } else if (tmpDWORD < 1 || MAXTRK <= tmpDWORD) {
  959.                         zmserror("track number is out of range.",line_,linebuf_,zms_,0,1);
  960.                     } else {
  961.                         int i, f = 0;
  962.                         for (i = 0; i < cominf->maxtrk; i++) {
  963.                             if (cominf->trkassign[i] == tmpDWORD) {
  964.                                 *trkdata[Trk].zmd++ = 0xCE;
  965.                                 *trkdata[Trk].zmd++ = i;    /* - 1; */
  966.                                 f = 1;
  967.                                 break;
  968.                             }
  969.                         }
  970.                         if (!f) {
  971.                             zmserror("illegal track number.",line_,linebuf_,zms_,0,1);
  972.                         } else {
  973.                             zmserror("restart(`j') will be ignored by many drivers.",line_,linebuf_,zms_ - 1,3,1);
  974.                         }
  975.                     }
  976.                 }
  977. #endif
  978.             case '?':
  979.                 for (trk = 0; target[trk] >= 0; trk++) {
  980.                     const int Trk = target[trk];
  981.                     BYTE rel = 0;
  982.                     DWORD address;
  983.                     line = line_;
  984.                     ld = ld_;
  985.                     zms = getnum2(zms_,&address,&err);
  986.                     if (err < 0) {
  987.                         zmserror("workarea control(`?') must be followed to its parameter.",line_,linebuf_,zms_,0,1);
  988.                     } else if (address < 0 || 255 < address) {
  989.                         zmserror("work address is out of range.",line_,linebuf_,zms_,0,1);
  990.                     }
  991.                     zms = skipSpcCr(zms);
  992.                     if (*zms != ',') {
  993.                         zmserror("workarea control(`?') must have 2 parameters.",line_,linebuf_,zms_,0,1);
  994.                     } else {
  995.                         zms = skipSpcCr(zms + 1);
  996.                     }
  997.                     if (*zms == '+' || *zms == '-') rel = 1;
  998.                     zms = getnum2(zms,&tmpDWORD,&err);
  999.                     if (err < 0) {
  1000.                         zmserror("workarea control(`?') must have 2 parameters.",line_,linebuf_,zms_,0,1);
  1001.                     } else {
  1002.                         if (!rel) {
  1003.                             *trkdata[Trk].zmd++ = 0xD5;
  1004.                             *trkdata[Trk].zmd++ = address;
  1005.                             *trkdata[Trk].zmd++ = tmpDWORD;
  1006.                         } else if (tmpDWORD < 0) {
  1007.                             *trkdata[Trk].zmd++ = 0xD8;
  1008.                             *trkdata[Trk].zmd++ = address;
  1009.                             *trkdata[Trk].zmd++ = -tmpDWORD;
  1010.                         } else {
  1011.                             *trkdata[Trk].zmd++ = 0xD7;
  1012.                             *trkdata[Trk].zmd++ = address;
  1013.                             *trkdata[Trk].zmd++ = tmpDWORD;
  1014.                         }
  1015.                         zmserror("workarea control(`?') will be ignored by many drivers.",line_,linebuf_,zms_ - 1,3,1);
  1016.                     }
  1017.                 }
  1018.                 break;
  1019.             case ';':
  1020.                 for (trk = 0; target[trk] >= 0; trk++) {
  1021.                     const int Trk = target[trk];
  1022.  
  1023.                     line = line_;
  1024.                     ld = ld_;
  1025.                     zms = zms_ - 1;
  1026.                     do {
  1027.                         zms = getnum2(zms + 1,&tmpDWORD,&err);
  1028.                         if (err < 0) break;
  1029.                         *trkdata[Trk].zmd++ = tmpDWORD;
  1030.                         zms = skipSpcCr(zms);
  1031.                     } while(*zms == ',');
  1032.                     zmserror("It's too dangerous to insert ZMD data directly.",line_,linebuf_,zms_ - 1,3,1);
  1033.                 }
  1034.                 break;
  1035. /* FM/ADPCMsupport by Mamiya END) */
  1036.             default:
  1037.                 {
  1038.                     UBYTE *zms2;
  1039.  
  1040.                     zms--;
  1041.                     makeZmdCommon(trkdata,zms,&zms2,cominf,1);
  1042.                     zms = zms2;
  1043.                 }
  1044. #ifdef A
  1045.                 if (*zms != ' ' && *zms != '\t' && *zms != 0x0d && *zms != 0x0a && *zms != 0x1a && *zms != 0xff) {
  1046.                     /* fprintf(stderr,"err! %.2X %c\n",*zms,*zms); */
  1047.                     zmserror("unknown MML.",line,linebuf,zms,2,1);
  1048.                 }
  1049.                 zms++;
  1050. #endif
  1051.                 break;
  1052.         }
  1053.         if (stat) {
  1054.             break;
  1055.         } else {
  1056.             for (trk = 0; target[trk] >= 0; trk++) {        /* memory leak check */
  1057.                 const int  Trk = target[trk];
  1058.                 const DWORD bs = trkdata[Trk].zmd - trkdata[Trk].zmdbuf;
  1059.  
  1060.                 if (bs > trkdata[Trk].bufsize - MTRK_OVERFLOW_RANGE) {
  1061.                     char s[32];
  1062.                     sprintf(s,"trkdata[%d].zmdbuf",Trk);
  1063.                     trkdata[Trk].bufsize += FIRST_MTRK_SIZE;
  1064.                     trkdata[Trk].zmdbuf = (UBYTE*)erealloc(trkdata[Trk].zmdbuf,sizeof(UBYTE) * trkdata[Trk].bufsize,s);
  1065.                     trkdata[Trk].zmd = trkdata[Trk].zmdbuf + bs;
  1066.                 }
  1067.             }
  1068.         }
  1069.     }
  1070.  
  1071.     *zms2 = zms;
  1072.     *totalstep = 0;
  1073.  
  1074.     if (!didPlayCommand)    {        /* without (p) command */
  1075.         if (cominf->backinuse) {    /* there is [back..] trk */
  1076.             setSwitchVal('z',3);    /* disable the trk deleting */
  1077.         }
  1078.     }
  1079.  
  1080.     {
  1081.         int i,j;
  1082. /*
  1083. fprintf(stderr,"[%d]",cominf->trkassign[0]);
  1084. fprintf(stderr,"[%d]",cominf->trkassign[1]);
  1085. */
  1086. /*
  1087.     for (i = 1; i < cominf->maxtrk; i++) {
  1088. */
  1089. /*memdebug();*/
  1090.         for (i = 0, j = 0; cominf->trkassign[i] >= 0; i++, j++) {
  1091.             const int Trk = cominf->trkassign[i];
  1092. /*
  1093.             const int Trk = i;
  1094. */
  1095.             char errmes[80];
  1096.  
  1097. /*fprintf(stderr,"[%d]",cominf->trkassign[i]);*/
  1098.             trkdata[Trk].nowsize = trkdata[Trk].zmd - trkdata[Trk].zmdbuf;
  1099. /*fprintf(stderr,"TrkSize=%d ",trkdata[Trk].nowsize);*/
  1100.  
  1101.             if (*totalstep < trkinf[Trk].total) {
  1102.                 *totalstep = trkinf[Trk].total;
  1103.             }
  1104. /*fprintf(stderr,"Trk%d: total %d\n",Trk,trkinf[Trk].total);*/
  1105.             if (trkdata[Trk].nowsize & 3) {                /* padding if need */
  1106.                 const int len = trkdata[Trk].nowsize & 3;
  1107.                 int j;
  1108.                 for (j = len; j < 4; j++) {
  1109.                     *trkdata[Trk].zmd++ = 0xFF;
  1110.                     trkdata[Trk].nowsize++;
  1111.                 }
  1112.             }
  1113.  
  1114.             freeAllChord(trkinf[Trk].c);
  1115. /* #ifdef A */
  1116.             if (trkinf[Trk].renpnotes) {
  1117.                 sprintf(errmes,"`}' is not closed in track %d.",Trk);
  1118.                 zmserror(errmes,line,linebuf,zms,0,0);
  1119.                 resetError();
  1120.             }
  1121.             if (trkinf[Trk].l->prev) {
  1122.                 if (trkinf[Trk].l->loopmode >= 0) {
  1123.                     sprintf(errmes,":| is not closed in track %d.",Trk);
  1124.                     zmserror(errmes,line,linebuf,zms,3,0);
  1125.                     resetError();
  1126.                 }
  1127.                 do {
  1128.                     trkinf[Trk].l = trkinf[Trk].l->prev;
  1129.                     efree(trkinf[Trk].l->next,"trkinf[Trk].l->next");
  1130.                 } while (trkinf[Trk].l->prev);
  1131.             }
  1132.             if (trkinf[Trk].d->looptime) {
  1133.                 sprintf(errmes,"[do]~[loop] is not closed in track %d.",Trk);
  1134.                 zmserror(errmes,line,linebuf,zms,3,0);
  1135.                 resetError();
  1136. /*
  1137.             do {
  1138.                 trkinf[Trk].d = trkinf[Trk].d->prev;
  1139.                 efree(trkinf[Trk].d->next);
  1140.             } while (trkinf[Trk].d->prev);
  1141. */
  1142.             }
  1143.             if (trkinf[Trk].s->prev) {
  1144.                 sprintf(errmes,"`}}' is not closed in track %d.",Trk);
  1145.                 zmserror(errmes,line,linebuf,zms,4,0);
  1146.                 resetError();
  1147.                 do {
  1148.                     trkinf[Trk].s = trkinf[Trk].s->prev;
  1149.                     efree(trkinf[Trk].s->next,"trkinf[Trk].s->next");
  1150.                 } while (trkinf[Trk].s->prev);
  1151.             }
  1152. /* #endif */
  1153. /*fprintf(stderr,"[freeTrkInf %d]\n",Trk);*/
  1154.             freeTrkInf(&trkinf[Trk],Trk);
  1155.         }
  1156. /*fprintf(stderr,"((%d))\n",j);*/
  1157.         for (i = 1; i < cominf->maxtrk; i++) {        /* no BACK trk supported */
  1158. /*fprintf(stderr,"[freeTrkInf %d]\n",i);*/
  1159.             freeTrkInf(&trkinf[i],i);
  1160.         }
  1161.     }
  1162.     efree(trkinf,"trkinf");
  1163.     efree(target,"target");
  1164.  
  1165.     return trkdata;
  1166. }
  1167.  
  1168.  
  1169.  
  1170.  
  1171.  
  1172.  
  1173. UBYTE *makeZmdNote(UBYTE *zms,TRKCHINF *trkdata, const BYTE target[],
  1174.                         TRKINF *trkinf,COMMONINF *cominf)
  1175. {
  1176.     int trk;
  1177.     char *zms_ = zms - 1;
  1178.     /* UBYTE *data_ = data; */
  1179.     DWORD    line_ = line;
  1180.     LINEDATA *ld_ = ld;
  1181.     VELOETCVAR v;
  1182.     int warnoct = 0;
  1183.     WORD velo;
  1184.  
  1185.     /* v = (VELOETCVAR*)emalloc(sizeof(VELOETCVAR) * 1); */
  1186.  
  1187.     for (trk = 0; target[trk] >= 0; trk++) {
  1188.         const int Trk = target[trk];
  1189.         BYTE    note,relvelo = 0;
  1190.         UWORD    step,gate,looptime = trkinf[Trk].echolp;
  1191.         /* DWORD    velo; */
  1192.         int        err,omitgate = 0;
  1193.         BYTE    *qpos = &(trkinf[Trk].quantizepos);
  1194.         const int beforeOctave = trkinf[Trk].octave;
  1195.         UBYTE    *linebuf_;
  1196.  
  1197.         v.var[0] = 0;
  1198.         v.relflg[0] = 2;
  1199.  
  1200.         /* data = data_; */
  1201.         line = line_;
  1202.         ld = ld_;
  1203.  
  1204.         /* note */
  1205.         zms = makeZmdNote1(zms_,Trk,trkinf,¬e);
  1206. /* printf("(%.2x)",note); */
  1207.         zms = checkOctaveChange(zms,trkinf,Trk);
  1208.  
  1209.         /* step */
  1210.         zms = getStep(zms, &step, trkinf[Trk].Step,&err,cominf);
  1211.         zms = checkOctaveChange(zms,trkinf,Trk);
  1212.  
  1213.         /* gate */
  1214.         zms = getGate(zms,Trk,trkinf,step,&gate,&omitgate,cominf);
  1215.         zms = checkOctaveChange(zms,trkinf,Trk);
  1216.  
  1217.         /* velo */
  1218.         zms = getSpecialVelocity(zms,&v);
  1219.         velo = setVelo0(trkdata,Trk,v,&relvelo,trkinf,cominf,step);
  1220.  
  1221.  
  1222.         linebuf_ = linebuf;
  1223.  
  1224.  
  1225.         zms = skipSpcCr(zms);
  1226.         zms = set98Tie(zms, &step, trkinf[Trk].Step, cominf, &err);
  1227.         if (omitgate == 2) {
  1228.             gate = getGate1(Trk,trkinf,step);
  1229.         }
  1230.         zms = skipSpcCr(zms);
  1231.         if (*zms == '&') {            /* tie */
  1232.             gate = 0x8000;
  1233.             zms++;
  1234.         }
  1235.  
  1236.  
  1237.         if (looptime != 1) {
  1238.             if (relvelo == 0) {
  1239.                 relvelo = 1;
  1240.                 velo = trkinf[Trk].echodec;
  1241.             }
  1242.             while ( (looptime > 1) || (looptime == 0) && (step > trkinf[Trk].echoitv) ) {
  1243. /* break when: (looptime == 1) || (looptime == 0 && step <= echoitv) */
  1244. /*
  1245. relvelo == 1: relative velo
  1246. relvelo == 0: detault velo
  1247. relvelo = -1: special velo
  1248. */
  1249.                 zms = setTie2(zms,trkdata,Trk,trkinf,
  1250.                                 note,trkinf[Trk].echoitv, trkinf[Trk].echoitv,
  1251.                                 relvelo,0,velo);
  1252.  
  1253.                 step -= trkinf[Trk].echoitv;
  1254.                 if (gate > trkinf[Trk].echoitv) {
  1255.                     gate -= trkinf[Trk].echoitv;
  1256.                 } else {
  1257.                     gate = 0;
  1258.                 }
  1259.                 velo += trkinf[Trk].echodec;
  1260.                 if (looptime) {
  1261.                     looptime--;
  1262.                 }
  1263. #ifdef A
  1264.                 zms = setTie(zms, trkdata, Trk, trkinf,                /* TIE */
  1265.                                 note, &step, gate, relvelo, omitgate,
  1266.                                 trkinf[Trk].Step,cominf,velo);
  1267. #endif
  1268.             }
  1269.  
  1270.         }
  1271.         zms = setTie(zms, trkdata, Trk, trkinf,                /* last 1 time */
  1272.                         note, &step, &gate, relvelo, omitgate,
  1273.                         trkinf[Trk].Step,cominf,velo);
  1274.  
  1275.         /* if (trkinf[Trk].quantize[++*qpos].relflg[0] < 0) { */
  1276.  
  1277.         if (++*qpos >= trkinf[Trk].quantizenum) {
  1278.             *qpos = 0;
  1279.         }
  1280.  
  1281.         if (gate == 0x8000 && beforeOctave != trkinf[Trk].octave && !warnoct && step != 1) {
  1282.             zmserror("There is octave switch(es) between NOTE and TIE.",line_,linebuf_,zms_,3,2);
  1283.             warnoct = 1;
  1284.         }
  1285.  
  1286.         incrementStepCounters(&trkinf[Trk], step);
  1287.         if (trkinf[Trk].veloseqsw) {        /* add v0.74 */
  1288.             vSeqLoopChk(Trk,trkinf);
  1289.         }
  1290. #ifdef AAA
  1291.         if (!trkinf[Trk].renpnotes) {
  1292.             trkinf[Trk].total += step;
  1293.             if (trkinf[Trk].s->prev) {
  1294.                 trkinf[Trk].s->step += step;
  1295.             }
  1296.         }
  1297. #endif
  1298.         if (gate != 0xFFFF) {
  1299.             freeAllChord(trkinf[Trk].c);
  1300.         } else {
  1301.             DWORD gatepos = trkdata[Trk].zmd - trkdata[Trk].zmdbuf;
  1302.  
  1303.             addNextChkChord(trkinf[Trk].c, note, gatepos, gate);
  1304.         }
  1305. /* fprintf(stderr,"(t=%d)",trkinf[Trk].total); */
  1306.     }
  1307.     return zms;
  1308. }
  1309.  
  1310.  
  1311.  
  1312.  
  1313.  
  1314. /* ==================
  1315.      get tone (sub)
  1316.    ================== */
  1317.  
  1318. UBYTE *makeZmdNote1(UBYTE *zms, const int Trk,TRKINF *trkinf,BYTE *note)
  1319. {
  1320.     /* const int Trk = target[trk]; */
  1321.     const BYTE tonetbl[7] = { 0, 2, 4, 5, 7, 9, 11 };
  1322.     const char *dstr_ = "#+--!";
  1323.     BYTE    d[3] = { 0, 0, 0 };            /* number of #+,b-,! */
  1324.     char *dstr;
  1325.  
  1326.     *note  = (*zms++ | 0x20) - 'a';
  1327.     *note -= 2;                            /* c→0 a→-2 */
  1328.     if (*note < 0) {
  1329.         *note += 7;
  1330.     }
  1331.     *note = tonetbl[*note];                    /* without #/b */
  1332.  
  1333.     zms = skipSpcCr(zms);
  1334.     while ( (dstr = strchr(dstr_,*zms)) != NULL) {
  1335.         d[((const char *)dstr - dstr_) / 2]++;
  1336.         if (d[2]) {
  1337.             if (d[2] > 1) {
  1338.                 zmserror("too many natural(!).",line,linebuf,zms,0,1);
  1339.             } else if (d[0] || d[1]) {
  1340.                 zmserror("natural(!) must be on just after note.",line,linebuf,zms,0,1);
  1341.             }
  1342.         }
  1343.         zms = skipSpcCr(++zms);
  1344.     }
  1345.  
  1346.     if (!d[2]) {
  1347.         *note += trkinf[Trk].ksign[*note % 12];        /* with KSIGN */
  1348.     }
  1349.     *note += d[0];
  1350.     *note -= d[1];                                /* #/b is reflected */
  1351. #ifdef A                                        /* you should omit transpose in V3 */
  1352.     *note += trkinf[Trk].transpose;                /* transpose is reflected  */
  1353. #endif
  1354.  
  1355.     *note += (trkinf[Trk].octave + 1) * 12;
  1356.                                                 /* #/b,transpose,octrave are reflected */
  1357.  
  1358.     return zms;
  1359. }
  1360.  
  1361.  
  1362. /* ======================
  1363.      get gate parameter
  1364.    ====================== */
  1365.  
  1366. UBYTE *getGate(UBYTE *zms, const int Trk,TRKINF *trkinf,UWORD step, UWORD *gate,int *err,
  1367.                 COMMONINF *cominf)
  1368. {
  1369.     /* const int Trk = target[trk]; */
  1370.  
  1371.     if (*zms == ',') {
  1372.         zms = getStep(++zms, gate, trkinf[Trk].Step, err, cominf);
  1373.         if (*err == 2) {                        /* if gate is omitted */
  1374.             *gate = getGate1(Trk,trkinf,step);
  1375.         }
  1376.     } else {
  1377.         *err = 2;
  1378.         *gate = getGate1(Trk,trkinf,step);
  1379.     }
  1380. /*
  1381.     if ((step < *gate) && step) {
  1382.         zmserror("step < gate.",line,linebuf,zms,3,1);
  1383.     }
  1384. */
  1385.  
  1386.     return zms;
  1387. }
  1388.  
  1389.  
  1390. /* ==
  1391.      portament/chord
  1392. */
  1393.  
  1394. UBYTE *makePortChord(UBYTE *zms, const int Trk,
  1395.                         TRKINF *trkinf,COMMONINF *cominf,
  1396.                         const UBYTE endchar,char allowcamma,
  1397.                         VELOETCVAR v[],BYTE note[],int *notes,
  1398.                         UWORD *step_, UWORD *gate_, UWORD *gate0,
  1399.                         WORD *delay, WORD *ptime)
  1400. {
  1401.     char *zms_ = zms - 1;
  1402.     char *linebuf_ = linebuf;
  1403.     DWORD    line_ = line;
  1404.     LINEDATA *ld_ = ld;
  1405. /*
  1406.     UBYTE *zms_ = zms;
  1407. */
  1408.  
  1409.     /* const int Trk = target[trk]; */
  1410.     UWORD step;
  1411.     int i,err,steps = 0;
  1412.     int beforeOctave = trkinf[Trk].octave;
  1413.     DWORD tmpDWORD;
  1414.     const UWORD Step = trkinf[Trk].Step;
  1415.     const BYTE portflg = (endchar == ')' || endchar == ']')? 1 : 0;
  1416.  
  1417.     *notes = 0;
  1418.     *step_ = trkinf[Trk].Step;
  1419.     *gate_ = getGate1(Trk,trkinf,*step_);
  1420.     /* *gate0 = *gate_; */        /* add v0.74 */
  1421.     /* *delay = trkinf[Trk].pdelay; */
  1422. /* fprintf(stderr,"[s=%d/g=%d/d=%d]",*step_,*gate_, *delay); */
  1423.  
  1424.     for (i = 0; (i < 8 + 1 && !(*notes)); ) {
  1425.         UBYTE *tmpzms;
  1426.  
  1427.         zms = skipSpc(zms);
  1428.         switch(*zms) {
  1429.             case 'a':    case 'A':    case 'b':    case 'B':
  1430.             case 'c':    case 'C':    case 'd':    case 'D':
  1431.             case 'e':    case 'E':    case 'f':    case 'F':
  1432.             case 'g':    case 'G':
  1433.                 err = 0;
  1434.  
  1435.                 zms = makeZmdNote1(zms,Trk,trkinf,¬e[i]);
  1436.                 zms = getStep(zms, &step,Step,&err,cominf);
  1437.                 if (err != 2) {
  1438.                     *gate_ = getGate1(Trk,trkinf,step);
  1439.                 }
  1440.  
  1441.                 /*if (!portflg) { */
  1442.                 {
  1443.                     UWORD newgate1, newgate2;
  1444.                     int omitgate;
  1445.                     int omitgate2;
  1446.                     int err98;
  1447.  
  1448.                     v[i].var[0] = 0;
  1449.                     v[i].relflg[0] = 2;
  1450.                     zms = getGate(zms,Trk,trkinf,step,&newgate1,&omitgate,cominf);
  1451.                     zms = getSpecialVelocity(zms,&v[i]);
  1452. /* fprintf(stderr,"{%d:%d/%d}",i,v[i].var[0],v[i].relflg[0]); */
  1453. /*
  1454.                     if (omitgate != 2) {
  1455.                         *gate_ = newgate1;
  1456.                     }
  1457. */
  1458.                     tmpzms = zms = skipSpc(zms);
  1459.                     zms = set98Tie(zms,&step,Step,cominf, &err98);
  1460.  
  1461.                     /*UWORD gate;*/
  1462.                     /*UWORD newgate;*/
  1463.                     /*v[i].var[0] = 0;*/
  1464.                     /* v[i].relflg[0] = 2; */
  1465.                     zms = getGate(zms,Trk,trkinf,step,&newgate2,&omitgate2,cominf);
  1466.                     zms = getSpecialVelocity(zms,&v[i]);
  1467. /* fprintf(stderr,"{{%d:%d/%d}}",i,v[i].var[0],v[i].relflg[0]); */
  1468.  
  1469.                     if (err != 2 || err98 != 2) {    /* step & gate will be change */
  1470.                                     /* err == 0: there is parameter */
  1471.                                     /*     == 1: only dot(.) there */
  1472.                                     /*     == 2: omit all parameters */
  1473.                         if (++steps > 1 && *step_ != step) {
  1474.                             zmserror("too many steps in a chord/portament.",line_,linebuf_,zms_,0,1);
  1475.                         } else {
  1476.                             *step_ = step;
  1477.  
  1478.                             if (omitgate2 == 2 && omitgate == 2) {
  1479.                                 *gate_ = getGate1(Trk,trkinf,*step_);
  1480.                             } else {
  1481.                                 if (omitgate != 2) {
  1482.                                     *gate_ = newgate1;
  1483.                                 } else {
  1484.                                     *gate_ = newgate2;
  1485.                                 }
  1486.                             }
  1487.                         }
  1488. /*fprintf(stderr,"[og1=%d og2=%d er=%d er2=%d]",omitgate, omitgate2, err,err98);*/
  1489.                     }
  1490.                 }
  1491.                 i++;
  1492.                 break;
  1493.             case 'o':
  1494.             case '<':    case '>':
  1495.                 zms = checkOctaveChange(zms,trkinf,Trk);
  1496.                 break;
  1497.             case ',':
  1498. #ifdef A
  1499.                 if (allowcamma) {
  1500.                     zms++;
  1501.                 } else {
  1502.                     zmserror("SYNTAX ERROR.",line_,linebuf_,zms_,0,1);
  1503.                 }
  1504. #endif
  1505.                 zms++;
  1506.                 break;
  1507.             case '\'':
  1508.             case '\"':
  1509.             case ')':
  1510.             case ']':
  1511.                 if (*zms == endchar) {
  1512.                     *notes = i;
  1513.                     zms++;
  1514.                 } else {
  1515.                     zmserror("SYNTAX ERROR.",line_,linebuf_,zms_,0,1);
  1516.                 }
  1517.                 break;
  1518.             default:
  1519.                 zmserror("SYNTAX ERROR.",line_,linebuf_,zms_,0,1);
  1520.                 break;
  1521.         }
  1522.     }
  1523.     if (!portflg) {
  1524.         trkinf[Trk].octave = beforeOctave;
  1525.     } else {
  1526.         beforeOctave = trkinf[Trk].octave;
  1527.     }
  1528.  
  1529.     zms = getnum2(zms,&tmpDWORD,&err);        /* gate */
  1530.     if (err >= 0) {                            /* there is a (ticked)step parameter */
  1531.         *step_ = tmpDWORD;
  1532.         *gate_ = getGate1(Trk,trkinf,*step_);
  1533.     } else     if (*zms == '*') {
  1534.         zms = getnum2(++zms,&tmpDWORD,&err);
  1535.         if (err >= 0) {                        /* there is a (ticked)step parameter */
  1536.             *step_ = tmpDWORD;
  1537.             *gate_ = getGate1(Trk,trkinf,*step_);
  1538.         }
  1539.     }
  1540.  
  1541.     zms = checkOctaveChange(zms,trkinf,Trk);
  1542.     if (*zms == ',') {                        /* delay */
  1543.         zms = skipSpcCr(zms + 1);
  1544. /*#ifdef A */
  1545.         if (*zms == '*') {
  1546.             zms++;
  1547.         }
  1548. /*#endif */
  1549.         zms = getnum2(zms,&tmpDWORD,&err);
  1550.         if (err) {
  1551.             zmserror("no delay parameter is specified.",line_,linebuf_,zms_,0,1);
  1552.         }
  1553.         *delay = tmpDWORD;
  1554.     }
  1555.  
  1556.     zms = checkOctaveChange(zms,trkinf,Trk);
  1557.     if (*zms == ',') {                        /* portament time */
  1558.         if (portflg) {
  1559.             zmserror("Portament time can't set on the chord.",line_,linebuf_,zms_,0,1);
  1560.         }
  1561.         zms = skipSpcCr(zms + 1);
  1562. #ifdef A
  1563.         if (*zms == '*') {
  1564.             zms++;
  1565.         }
  1566. #endif
  1567.         zms = getnum2(zms,&tmpDWORD,&err);
  1568.         if (err) {
  1569.             zmserror("no portament time is specified.",line_,linebuf_,zms_,0,1);
  1570.         }
  1571.         *ptime = tmpDWORD;
  1572.     }
  1573.     zms = checkOctaveChange(zms,trkinf,Trk);
  1574.  
  1575.     zms = skipSpcCr(zms);
  1576.     zms = set98Tie(zms,step_,Step,cominf,&err);
  1577.     /* *gate_ = getGate1(Trk,trkinf,*step_); */
  1578.     zms = skipSpcCr(zms);
  1579.  
  1580.     *gate0 = *gate_;        /* add v0.74 */
  1581. /* fprintf(stderr,"[s=%d/g=%d/d=%d]",*step_,*gate_, *delay); */
  1582.  
  1583.     if (*zms == '&') {            /* tie */
  1584.         *gate_ = (portflg)? 0x8000 : 0xFFFF;
  1585.         if (beforeOctave != trkinf[Trk].octave) {
  1586.             zmserror("There is octave switch(es) between NOTE and TIE.",line_,linebuf_,zms_,3,1);
  1587.         }
  1588.         zms++;
  1589.     }
  1590. /*fprintf(stderr,"[s=%d/g=%d/d=%d]",*step_,*gate_, *delay);*/
  1591.     if (*delay > *gate_) {
  1592. /*fprintf(stderr,"[g=%d/d=%d]",*gate_, *delay);*/
  1593.         zmserror("delay must be less than the gate.",line_,linebuf_,zms_,0,1);
  1594.     }
  1595. #ifdef A
  1596.     if (*step_ == 1 && cominf->l1tie) {        /* gate is *1 */
  1597.         *gate_ = 0xFFFF;
  1598.     }
  1599. #endif
  1600.  
  1601.     return zms;
  1602. }
  1603.  
  1604.  
  1605.  
  1606.  
  1607.  
  1608. UBYTE *makePlayTrack(UBYTE *zms,TRKINF *trkinf,TRKCHINF *trkdata,
  1609.                         COMMONINF *cominf,BYTE target[],int mode)
  1610.     /* mode=0: .track 1:(t) */
  1611. {
  1612.     int c = 0, err;
  1613.     DWORD trk;
  1614.     const char endchar[2] = { '{' , ')' };
  1615.     const char *endchar2[2] = { ",{", ",)" };
  1616.  
  1617.  
  1618.     if (cominf->trackmode) {
  1619.         zmserror("'}' is not closed.",line,linebuf,zms,0,1);
  1620.     } else {
  1621.         cominf->trackmode = 1 - mode;
  1622.     }
  1623.  
  1624.     while (*zms != endchar[mode]) {
  1625.         int i = 0 - 1,chkflag = 0;
  1626.         char errstr[80];
  1627.  
  1628.         zms = getnum2(zms,&trk,&err);
  1629.         if (err && c == 0 && *zms == endchar[mode] ) {    /* (t) */
  1630.             zmserror("no track number is assigned.",line,linebuf,zms,0,1);
  1631.         }
  1632. /*
  1633. fprintf(stderr,"Request:%d\n",trk);
  1634. while (cominf->trkassign[++i] >= 0) {
  1635. fprintf(stderr,"[%d_%d]",i,cominf->trkassign[i]);
  1636. }
  1637.         i = 0 - 1;
  1638. */
  1639.         while (cominf->trkassign[++i] >= 0) {
  1640.             if (cominf->trkassign[i] == trk) {
  1641.                 chkflag = 1;
  1642.                 break;
  1643.             }
  1644.         }
  1645. /*fprintf(stderr,"cf=%d",chkflag);*/
  1646.         if (!chkflag) {
  1647.             if (0 < trk && trk < 16) {        /* omit (AMIDIn,n) */
  1648.                 BYTE trks;
  1649.                 for (trks = 0; cominf->trkassign[trks] >= 0; trks++) {
  1650.                 }
  1651.  
  1652.                 makeZmdAssignMain(trkdata, cominf, trk, &trks, trk - 1, 0x8000);
  1653.                 /* initTrkInf0(trkdata, cominf->trkassign[trks - 1]); */
  1654.  
  1655.                 sprintf(errstr,"track %d is not assigned; (AMIDI%d,%d) is made up.",trk,trk,trk);
  1656.                 zmserror(errstr,line,linebuf,zms,3,1);
  1657.             } else if (trk <= 0) {
  1658.                 zmserror("illegal track number is specified.",line,linebuf,zms,0,1);
  1659.             } else {
  1660.                 sprintf(errstr,"track %d is not assigned.",trk);
  1661.                 zmserror(errstr,line,linebuf,zms,0,1);
  1662.             }
  1663.         }
  1664.         while (trkdata[trk].backinuse >= 0) {
  1665.             trk = trkdata[trk].backinuse;
  1666.         }
  1667.         target[c++] = trk;
  1668.         target[c]   = -1;
  1669.  
  1670.         zms = skipSpc(zms);
  1671.         if (!strchr( endchar2[mode], *zms)) {
  1672.             /* char str[128]; */
  1673.             /* sprintf(str,"%.2x illegal partion character.",*zms); */
  1674.             /* fprintf(stderr,"[%c]\n",*zms); */
  1675.             zmserror("illegal partition character.",line,linebuf,zms,0,1);
  1676.         }
  1677.         if (*zms == ',') {
  1678.             zms++;
  1679.         } else if (*zms == 0xFF && *(zms + 1) == 0xFF) {    /* EOF */
  1680.             zmserror("unexpected EOF.",line,linebuf,zms,0,1);
  1681.         }
  1682.     }
  1683.  
  1684.     zms++;
  1685. /*
  1686.     printf("Target:");
  1687.     for (trk = 0; target[trk] >= 0; trk++) {
  1688.         printf("%d,",target[trk]);
  1689.     }
  1690.     printf("\n");
  1691. */
  1692.  
  1693.     return zms;
  1694. }
  1695.